home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ksycoca.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-14  |  4.5 KB  |  187 lines

  1. /*  This file is part of the KDE libraries
  2.  *  Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
  3.  *
  4.  *  This library is free software; you can redistribute it and/or
  5.  *  modify it under the terms of the GNU Library General Public
  6.  *  License version 2 as published by the Free Software Foundation;
  7.  *
  8.  *  This library is distributed in the hope that it will be useful,
  9.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.  *  Library General Public License for more details.
  12.  *
  13.  *  You should have received a copy of the GNU Library General Public License
  14.  *  along with this library; see the file COPYING.LIB.  If not, write to
  15.  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.  *  Boston, MA 02110-1301, USA.
  17.  **/
  18.  
  19. #ifndef __ksycoca_h__
  20. #define __ksycoca_h__
  21.  
  22. #include <dcopobject.h>
  23. #include <qobject.h>
  24. #include <qstringlist.h>
  25. #include "ksycocatype.h"
  26. #include <kdelibs_export.h>
  27.  
  28. class QDataStream;
  29. class KSycocaPrivate;
  30. class KSycocaFactory;
  31. class KSycocaFactoryList;
  32.  
  33. /*
  34.  * Sycoca file version number.
  35.  * If the existing file is outdated, it will not get read
  36.  * but instead we'll ask kded to regenerate a new one...
  37. */
  38. #define KSYCOCA_VERSION 94
  39.  
  40. /**
  41.  * @internal
  42.  * Read-only SYstem COnfiguration CAche
  43.  */
  44. class KDECORE_EXPORT KSycoca : public QObject, public DCOPObject
  45. {
  46.   Q_OBJECT
  47.   K_DCOP
  48.  
  49. protected:
  50.    /**
  51.     * @internal
  52.     * Building database
  53.     */
  54.    KSycoca( bool /* buildDatabase */ );
  55.  
  56. public:
  57.  
  58.    /**
  59.     * Read-only database
  60.     */
  61.    KSycoca();
  62.  
  63.    /**
  64.     * Get or create the only instance of KSycoca (read-only)
  65.     */
  66.    static KSycoca *self();
  67.  
  68.    virtual ~KSycoca();
  69.  
  70.    static int version();
  71.  
  72.    /**
  73.     * @internal - called by factories in read-only mode
  74.     * This is how factories get a stream to an entry
  75.     */
  76.    QDataStream *findEntry(int offset, KSycocaType &type);
  77.    /**
  78.     * @internal - called by factories in read-only mode
  79.     */
  80.    QDataStream *findFactory( KSycocaFactoryId id);
  81.    /**
  82.     * @internal - returns kfsstnd stored inside database
  83.     */
  84.    QString kfsstnd_prefixes();
  85.    /**
  86.     * @internal - returns language stored inside database
  87.     */
  88.    QString language();
  89.  
  90.    /**
  91.     * @internal - returns timestamp of database
  92.     *
  93.     * The database contains all changes made _before_ this time and
  94.     * _might_ contain changes made after that.
  95.     */
  96.    Q_UINT32 timeStamp();
  97.  
  98.    /**
  99.     * @internal - returns update signature of database
  100.     *
  101.     * Signature that keeps track of changes to
  102.     * $KDEDIR/share/services/update_ksycoca
  103.     *
  104.     * Touching this file causes the database to be recreated
  105.     * from scratch.
  106.     */
  107.    Q_UINT32 updateSignature();
  108.  
  109.    /**
  110.     * @internal - returns all directories with information
  111.     * stored inside sycoca.
  112.     */
  113.    QStringList allResourceDirs();
  114.  
  115.    /**
  116.     * @internal - add a factory
  117.     */
  118.    void addFactory( KSycocaFactory * );
  119.  
  120.    /**
  121.     * @internal
  122.     * @return true if building (i.e. if a KBuildSycoca);
  123.     */
  124.    virtual bool isBuilding() { return false; }
  125.  
  126.    /**
  127.     * @internal - disables launching of kbuildsycoca
  128.     */
  129.    void disableAutoRebuild();
  130.  
  131.    /**
  132.     * Determine relative path for a .desktop file from a full path and a resource name
  133.     */
  134.    static QString determineRelativePath( const QString & _fullpath, const char *_resource );
  135.  
  136.    /**
  137.     * When you receive a "databaseChanged" signal, you can query here if
  138.     * a change has occurred in a specific resource type.
  139.     * @see KStandardDirs for the various resource types.
  140.     */
  141.    static bool isChanged(const char *type);
  142.  
  143.    /**
  144.     * A read error occurs.
  145.     */
  146.    static void flagError();
  147.  
  148.    /**
  149.     * Returns read error status and clears flag.
  150.     */
  151.    static bool readError();
  152.  
  153. k_dcop:
  154.    /**
  155.     * internal function for receiving kded/kbuildsycoca's signal, when the sycoca file changes
  156.     */
  157.    void notifyDatabaseChanged(const QStringList &);
  158.  
  159. signals:
  160.    /**
  161.         * Connect to this to get notified when the database changes
  162.         * (Usually apps showing icons do a 'refresh' to take into account the new mimetypes)
  163.         */
  164.    void databaseChanged();
  165.  
  166. protected:
  167.    bool checkVersion(bool abortOnError=true);
  168.    bool openDatabase(bool openDummyIfNotFound=true);
  169.    void closeDatabase();
  170.    KSycocaFactoryList *m_lstFactories;
  171.    QDataStream *m_str;
  172.    bool bNoDatabase;
  173.    size_t m_sycoca_size;
  174.    const char *m_sycoca_mmap;
  175.    Q_UINT32 m_timeStamp;
  176.  
  177. public:
  178.    static KSycoca *_self; // Internal use only.
  179.  
  180. protected:
  181.   virtual void virtual_hook( int id, void* data );
  182. private:
  183.    KSycocaPrivate *d;
  184. };
  185.  
  186. #endif
  187.